﻿using System;
using Core.Framework.Model.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace Core.DataAccess.Model.Project.Order
{
    /// <summary>
    /// 订单模块
    /// </summary>
    public partial class ProjectOrderContext : BaseDbContext<ProjectOrderContext>
    {
        public ProjectOrderContext()
        {
        }

        public ProjectOrderContext(bool isReader) : base(isReader)
        {
        }

        public ProjectOrderContext(DbContextOptions<ProjectOrderContext> options)
            : base(options)
        {
        }

        public virtual DbSet<OrderAccident> OrderAccident { get; set; }
        public virtual DbSet<OrderAddress> OrderAddress { get; set; }
        public virtual DbSet<OrderBasis> OrderBasis { get; set; }
        public virtual DbSet<OrderExpress> OrderExpress { get; set; }
        public virtual DbSet<OrderLog> OrderLog { get; set; }
        public virtual DbSet<OrderPay> OrderPay { get; set; }
        public virtual DbSet<OrderProduct> OrderProduct { get; set; }
        public virtual DbSet<OrderRefund> OrderRefund { get; set; }
        public virtual DbSet<OrderReturns> OrderReturns { get; set; }
        public virtual DbSet<OrderServe> OrderServe { get; set; }
        public virtual DbSet<OrderShipments> OrderShipments { get; set; }
        public virtual DbSet<OrderUserCart> OrderUserCart { get; set; }
        public virtual DbSet<OrderUserAddress> OrderUserAddress { get; set; }
        public virtual DbSet<OrderCoupon> OrderCoupon { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder
                    // 数据操作日志
                    //.UseLoggerFactory(EFLogger.GetLoggerFactory())
                    .UseSqlServer(CoreStartupHelper.GetConnectionValue("Order_SqlServerConnection"));
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<OrderAccident>(entity =>
            {
                entity.ToTable("order_accident");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.CompleteTime)
                    .HasColumnName("complete_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.EndTime)
                    .HasColumnName("end_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.Price)
                    .HasColumnName("price")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.ProductCount)
                    .HasColumnName("product_count")
                    .HasColumnType("decimal(18, 5)")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.ProductKey)
                    .HasColumnName("product_key")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Type).HasColumnName("type");

                entity.Property(e => e.UpdateLastTime)
                    .HasColumnName("update_last_time")
                    .HasColumnType("datetime");
            });

            modelBuilder.Entity<OrderAddress>(entity =>
            {
                entity.ToTable("order_address");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.CompleteTime)
                    .HasColumnName("complete_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.EndTime)
                    .HasColumnName("end_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.ProductKey)
                    .HasColumnName("product_key")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.UpdateLastTime)
                    .HasColumnName("update_last_time")
                    .HasColumnType("datetime");
            });

            modelBuilder.Entity<OrderBasis>(entity =>
            {
                entity.HasKey(e => e.OrderKey);

                entity.ToTable("order_basis");

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.CompleteTime)
                    .HasColumnName("complete_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.DiscountPrice)
                    .HasColumnName("discount_price")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.EndTime)
                    .HasColumnName("end_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.OrderStatus).HasColumnName("order_status");

                entity.Property(e => e.OrderType)
                    .HasColumnName("order_type")
                    .HasDefaultValueSql("((1))");

                entity.Property(e => e.Payment)
                    .HasColumnName("payment")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.Phone)
                    .IsRequired()
                    .HasColumnName("phone")
                    .HasMaxLength(11)
                    .IsUnicode(false);

                entity.Property(e => e.Price)
                    .HasColumnName("price")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.ProjectToken)
                    .IsRequired()
                    .HasColumnName("project_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.UpdateLastTime)
                    .HasColumnName("update_last_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.UserKey).HasColumnName("user_key");
            });

            modelBuilder.Entity<OrderExpress>(entity =>
            {
                entity.ToTable("order_express");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Name)
                    .IsRequired()
                    .HasColumnName("name")
                    .HasMaxLength(20)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Type)
                    .IsRequired()
                    .HasColumnName("type")
                    .HasMaxLength(10)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<OrderLog>(entity =>
            {
                entity.ToTable("order_log");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Type).HasColumnName("type");

                entity.Property(e => e.UserKey).HasColumnName("user_key");
            });

            modelBuilder.Entity<OrderPay>(entity =>
            {
                entity.ToTable("order_pay");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.Payment)
                    .HasColumnName("payment")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.UserKey).HasColumnName("user_key");
            });

            modelBuilder.Entity<OrderProduct>(entity =>
            {
                entity.ToTable("order_product");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.CompleteTime)
                    .HasColumnName("complete_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.DeliverGoods)
                    .HasColumnName("deliver_goods")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.DeliverGoodsCount)
                    .HasColumnName("deliver_goods_count")
                    .HasColumnType("decimal(18, 5)")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.DeliverGoodsType)
                    .HasColumnName("deliver_goods_type")
                    .HasDefaultValueSql("((1))");

                entity.Property(e => e.DiscountPrice)
                    .HasColumnName("discount_price")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.EndTime)
                    .HasColumnName("end_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.ExpressType)
                    .HasColumnName("express_type")
                    .HasDefaultValueSql("((1))");

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.Price)
                    .HasColumnName("price")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.ProductCount)
                    .HasColumnName("product_count")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.ProductInfo)
                    .HasColumnName("product_info")
                    .IsUnicode(false);

                entity.Property(e => e.ProductKey).HasColumnName("product_key");

                entity.Property(e => e.ProductType)
                    .HasColumnName("product_type")
                    .HasDefaultValueSql("((1))");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.SupplierKey).HasColumnName("supplier_key");

                entity.Property(e => e.UpdateLastTime)
                    .HasColumnName("update_last_time")
                    .HasColumnType("datetime");
            });

            modelBuilder.Entity<OrderRefund>(entity =>
            {
                entity.ToTable("order_refund");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.CompleteTime)
                    .HasColumnName("complete_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.EndTime)
                    .HasColumnName("end_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.OrderRefundKey).HasColumnName("order_refund_key");

                entity.Property(e => e.Payment)
                    .HasColumnName("payment")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.Price)
                    .HasColumnName("price")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Statu).HasColumnName("statu");

                entity.Property(e => e.UpdateLastTime)
                    .HasColumnName("update_last_time")
                    .HasColumnType("datetime");
            });

            modelBuilder.Entity<OrderReturns>(entity =>
            {
                entity.ToTable("order_returns");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.CompleteTime)
                    .HasColumnName("complete_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.EndTime)
                    .HasColumnName("end_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.ProductCount)
                    .HasColumnName("product_count")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.ProductKey).HasColumnName("product_key");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Statu)
                    .HasColumnName("statu")
                    .HasDefaultValueSql("((1))");

                entity.Property(e => e.UpdateLastTime)
                    .HasColumnName("update_last_time")
                    .HasColumnType("datetime");
            });

            modelBuilder.Entity<OrderServe>(entity =>
            {
                entity.ToTable("order_serve");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.CompleteTime)
                    .HasColumnName("complete_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.EndTime)
                    .HasColumnName("end_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.ProductKey)
                    .HasColumnName("product_key")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.UpdateLastTime)
                    .HasColumnName("update_last_time")
                    .HasColumnType("datetime");
            });

            modelBuilder.Entity<OrderShipments>(entity =>
            {
                entity.ToTable("order_shipments");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.CompleteTime)
                    .HasColumnName("complete_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.EndTime)
                    .HasColumnName("end_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.ExpressCode)
                    .HasColumnName("express_code")
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.ExpressName)
                    .HasColumnName("express_name")
                    .HasMaxLength(20)
                    .IsUnicode(false);

                entity.Property(e => e.ExpressType)
                    .HasColumnName("express_type")
                    .HasMaxLength(10)
                    .IsUnicode(false);

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.ProductCount)
                    .HasColumnName("product_count")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.ProductKey).HasColumnName("product_key");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.ShipmentsType).HasColumnName("shipments_type");

                entity.Property(e => e.UpdateLastTime)
                    .HasColumnName("update_last_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.UserKey).HasColumnName("user_key");
            });

            modelBuilder.Entity<OrderUserCart>(entity =>
            {
                entity.ToTable("order_user_cart");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.CompleteTime)
                    .HasColumnName("complete_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.DisCountPrice)
                    .HasColumnName("dis_count_price")
                    .HasColumnType("decimal(18, 5)")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.EndTime)
                    .HasColumnName("end_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Phone)
                    .IsRequired()
                    .HasColumnName("phone")
                    .HasMaxLength(11)
                    .IsUnicode(false);

                entity.Property(e => e.Price)
                    .HasColumnName("price")
                    .HasColumnType("decimal(18, 5)")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.ProductCount)
                    .HasColumnName("product_count")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.ProductKey).HasColumnName("product_key");

                entity.Property(e => e.ProjectToken)
                    .IsRequired()
                    .HasColumnName("project_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.SupplierKey).HasColumnName("supplier_key");

                entity.Property(e => e.UpdateLastTime)
                    .HasColumnName("update_last_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.UserKey).HasColumnName("user_key");
            });
        }
    }
}
